<template>
  <div class="form">
    <!-- 表单 -->
    <el-form
      ref="formRef"
      class="form-content"
      label-position="top"
      :model="formData"
      status-icon
      :rules="formRules"
    >
      <!-- 用户名 -->
      <el-form-item label="" prop="username">
        <el-input
          v-model="formData.username"
          maxlength="20"
          size="large"
          placeholder="请输入账号"
        ></el-input>
      </el-form-item>
      <!-- 密码 -->
      <el-form-item label="" prop="password">
        <el-input
          v-model="formData.password"
          type="password"
          size="large"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <!-- 记住密码 忘记密码？ -->
      <el-form-item>
        <div class="form-change">
          <el-text
            class="forget-password"
            type="primary"
            @click="forgetPassword"
          >
            忘记密码？
          </el-text>
        </div>
      </el-form-item>
      <!-- 登录 -->
      <el-form-item>
        <el-button
          class="form-button"
          color="#626aef"
          size="large"
          :loading="loading"
          @click.prevent="login"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ElMessage } from 'element-plus'
import { reactive, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'

// el-form
const formRef = ref()
const formData = reactive({
  username: 'admin',
  password: '123456',
  remember: false
})
const formRules = reactive({
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
    { min: 4, max: 20, message: '用户名长度在4到20字符之间', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 4, max: 20, message: '密码长度在4到20字符之间', trigger: 'blur' }
  ]
})

// loading
const loading = ref(false)

// login
const router = useRouter()
const route = useRoute()
const login = () => {
  // const redirect = route.query.redirect || '/home'
  // router.push(redirect)
  ElMessage.error('暂不支持，请使用短信验证码登录')
}
// forget
const forgetPassword = () => {}
</script>

<style lang="less" scoped>
.form-change {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}
.forget-password {
  cursor: pointer;
}
.form-button {
  width: 100%;
  & + .form-button {
    margin-left: 0;
    margin-top: 20px;
  }
}

:deep(.el-form-item) {
  margin-bottom: 24px;
}
</style>
